package com.ccrego.haiyi.common.web;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.baseuicomponent.fragment.BaseFragment;
import com.pachong.android.framework.R;

/**
 * 通用的Webview Activity
 *
 * @Author: PengWeiwei
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016/4/21 17:15
 * Version: 1.0.0
 */
public class CommonWebViewActivity extends BaseActivity {
    private static final String EXTRA_URL = "extra_url";

    private String mUrl;
    private BaseFragment mWebviewFragment;

    public static void start(Context context, String url) {
        Intent starter = new Intent(context, CommonWebViewActivity.class);
        starter.putExtra(EXTRA_URL, url);
        context.startActivity(starter);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_common_webview, null);
        return view;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideToolbar();
        mUrl = getIntent().getStringExtra(EXTRA_URL);
        mUrl = "file:///android_asset/www/test_web_mobile_pic_picker.html";
        Log.e("vivi", "   mUrl  = " + mUrl);
        mWebviewFragment = X5CommonWebviewFragment.newInstance(mUrl);
        getSupportFragmentManager().beginTransaction().add(R.id.flytWebview, mWebviewFragment).commit();
    }

    protected <V extends BaseFragment> V getWebviewFragment() {
        return (V) mWebviewFragment;
    }

    protected <V extends BaseFragment> V createWebviewFragment() {
        return (V)X5CommonWebviewFragment.newInstance(mUrl);
    }

}
